<template>
  <div class="app-container">
    <el-form :model="form"  label-width="120px" ref="copyRightForm">

      <el-form-item label="版权LOGO" prop="logo" required="">
        <img @click="showImageCenter"  v-if="form.logo" :src="form.logo" class="avatar">
        <i v-else @click="showImageCenter" class="el-icon-plus avatar-uploader-icon"></i>

      </el-form-item>

      <el-form-item label="公司名称" prop="company">
        <el-input v-model="form.company" placeholder="公司名称" style="width:180px"/>
      </el-form-item>

      <el-form-item label="版权链接" prop="link">
        <el-input v-model="form.link" placeholder="版权链接" style="width:300px"/>
      </el-form-item>

      <el-form-item label="版权说明" prop="link">
        <el-input v-model="form.content" placeholder="版权说明" style="width:300px"/>
      </el-form-item>
     
      <el-form-item>
        <el-button type="primary" @click="onSubmit('copyRightForm')">提 交</el-button>
        <el-button @click="onCancel()">重置</el-button>
      </el-form-item>
    </el-form>
    <ImageCenter :is_multiple=false :Innervisible.sync="dialogImageVisible" :limit=1  @change="changeImage" @closeImage="closeImage"/>
  </div>
</template>

<script>
  import {getConfig,addOrUpdateConfig} from '@/api/config/config'
  import ImageCenter from '@/components/ImageCenter'
export default {
  components: {ImageCenter},
  data() {
    return {
      form: {
        logo: '',
        company: '',
        link: '',
        content: '',
      },
      configKey:'copyRight',
      dialogImageVisible:false
    }
  },
  beforeMount() {
    getConfig(this.configKey).then(response => {
      if(response.data == '') return;

      if(typeof(response.data) == "object"){
        this.form = response.data
      }
      if(typeof(response.data) == "string"){return;}
      //this.form = response.data
    })
  },
  methods: {
    onSubmit(formName) {
      let data = {};
      data.key = this.configKey;
      data.data = this.form;

      addOrUpdateConfig(data).then(response => {
        if(response.code == 200){
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          // setTimeout(()=>{
          //   this.$router.push({name:'announcement'});
          // }, 200)
        }
      })
    },

    showImageCenter() {
      this.dialogImageVisible = true;
      return false;
    },
    changeImage:function(res){
      this.dialogImageVisible = false;
      if(res.length == 1){
        this.form.logo = res[0].url
      }
    },
    closeImage:function(){
      this.dialogImageVisible = false;
    },
    onCancel() {
      this.$message({
        message: 'cancel!',
        type: 'warning'
      })
    },
  }
}
</script>

<style scoped>
  .line{
    text-align: center;
  }
.app-container {
  background: #fff;
  margin-top: 18px;
  height: 100%;
  min-height: calc(100vh - 68px);
  font-size: 12px
}

.app-container * {
  font-size: 12px;
}
.avatar,.avatar-uploader-icon {
  width: 90px;
  height: 90px;
  padding: 1px;
  border: 1px solid #ccc;
  text-align: center;
  line-height: 90px;
}
</style>
